<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>宿舍房间列表</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css">
</head>
<body>
<div class="container mt-4">
    <h2>宿舍房间列表</h2>

    <div th:if="${message}" class="alert alert-success" th:text="${message}"></div>
    <div th:if="${error}" class="alert alert-danger" th:text="${error}"></div>

    <a th:href="@{/dormrooms/add}" class="btn btn-primary mb-3">添加宿舍房间</a>
    <a href="/index">返回首页</a>

    <table class="table table-striped">
        <thead>
        <tr>
            <th>ID</th>
            <th>宿舍楼</th>
            <th>房间号</th>
            <th>类型</th>
            <th>当前人数</th>
            <th>最大容量</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="room : ${dormRooms}">
            <td th:text="${room.id}"></td>
            <td th:text="${room.building.buildingName}"></td>
            <td th:text="${room.roomNumber}"></td>
            <td th:text="${room.type.typeName}"></td>
            <td th:text="${room.currentCapacity}"></td>
            <td th:text="${room.maxCapacity}"></td>
            <td th:text="${room.status}"></td>
            <td>
                <a th:href="@{/dormrooms/view/} + ${room.id}" class="btn btn-info btn-sm">查看</a>
                <a th:href="@{/dormrooms/edit/} + ${room.id}" class="btn btn-warning btn-sm">编辑</a>
                <a th:href="@{/dormrooms/delete/} + ${room.id}" class="btn btn-danger btn-sm"
                   onclick="return confirm('确定要删除这个房间吗？')">删除</a>
            </td>
        </tr>
        </tbody>
    </table>
</div>
</body>
</html>